package ebj.common.utils;

import java.util.LinkedList;

public class StringUtils {
	/**
	 * 方法名     : isEmpty
	 * 描述: <p>判断参数字符串是否为空，为空则返回true，否则返回false</p>
	 * @modify by  : 
	 * @modify date:
	 * @param sourceStr
	 * @return
	 * ADD BY zhouxy AT TIME 2013-1-6 下午2:51:59
	 */
	public static boolean isEmpty(String sourceStr) {
		//...
		sourceStr = sourceStr.replaceAll("\\s", "");
		if (sourceStr == null || sourceStr.length() <= 0) {
			return true;
		}
		return false;
	}
	
	
	/**
	 * 方法名     : rmBlankSpace
	 * 描述: <p>去除参数字符串中的所有空格</p>
	 * @modify by  : 
	 * @modify date:
	 * @param sourceStr
	 * @return
	 * ADD BY zhouxy AT TIME 2013-1-6 下午2:55:42
	 */
	public static String rmBlankSpace(String sourceStr) {
		//...
		sourceStr = sourceStr.replace(" ", "");
		return sourceStr;
	}
	
	/**
	 * 方法名     : rmWhiteSpace
	 * 描述: <p>去除参数字符串当中的所有空白字符，包括回车、换行符、制表符 和 所有空格</p>
	 * @modify by  : 
	 * @modify date:
	 * @param sourceStr
	 * @return
	 * ADD BY zhouxy AT TIME 2013-1-6 下午2:58:18
	 */
	public static String rmWhiteSpace(String sourceStr) {
		//...
		sourceStr = sourceStr.replaceAll("\\s", "");
		return sourceStr;
	}
	
	/**
	 * 方法名     : explode
	 * 描述: <p>将参数字符串按照分隔符expr分割成数组</p>
	 * @modify by  : 
	 * @modify date:
	 * @param sourceStr
	 * @param expr
	 * @return
	 * ADD BY zhouxy AT TIME 2013-1-6 下午3:04:31
	 */
	public static String[] explode(String sourceStr, String expr) {
		String[] a = sourceStr.split(expr);
		return a;
	}
	
	/**
	 * 方法名     : implode
	 * 描述: <p>将字符数组的元素用分隔符连接成字符串</p>
	 * @modify by  : 
	 * @modify date:
	 * @param sourceArr
	 * @param expr
	 * @return
	 * ADD BY zhouxy AT TIME 2013-1-7 下午4:07:49
	 */
	public static String implode(String[] sourceArr, String expr) {
		//...
		String rsStr = "";
		StringBuffer stringBuffer = new StringBuffer();
		for (int i = 0; i < sourceArr.length; i++) {
			if (i < sourceArr.length - 1) {
				stringBuffer.append(sourceArr[i] + expr);
			}else {
				stringBuffer.append(sourceArr[i]);
			}
		}
		rsStr = stringBuffer.toString();
		return rsStr;
	}
	
	/**
	 * 方法名     : reverse
	 * 描述: <p>将参数字符串按照逆序，排列成新的字符串</p>
	 * @modify by  : 
	 * @modify date:
	 * @param sourceStr
	 * @return
	 * ADD BY zhouxy AT TIME 2013-1-7 下午4:21:15
	 */
	public String reverse(String sourceStr) {
		String rsStr = "";
		char[] chars = sourceStr.toCharArray();
		StringBuffer stringBuffer = new StringBuffer();
		
		for (int i = 0; i < chars.length; i++) {
			stringBuffer.append(chars[chars.length - i - 1]);
		}
		rsStr = stringBuffer.toString();
		return rsStr;
	}
	
	public String rmRepeat(String sourceStr) {
		StringBuffer stringBuffer = new StringBuffer();
		char[] chars = sourceStr.toCharArray();
		LinkedList<String> list1 = new LinkedList<String>();
		LinkedList<String> list2 = new LinkedList<String>();
				
		for (int i = 0; i < chars.length; i++) {
			if (list1.contains(String.valueOf(chars[i]))) {
				list2.add(String.valueOf(chars[i]));
			}else {
				list1.add(String.valueOf(chars[i]));
			}
		}
		
		for (String string : list1) {
			stringBuffer.append(string);
		}
		
		return stringBuffer.toString();
	}
}
